package top.lshaci.learning.nio;

import cn.hutool.core.util.StrUtil;

import java.io.FileInputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;

/**
 * NioFileChannelRead
 *
 * @author lshaci
 * @since 1.0.0
 */
public class NioFileChannelRead {

    public static void main(String[] args) throws Exception {
        String filename = "E:/NIO1.txt";
        FileInputStream fis = new FileInputStream(filename);

        final FileChannel channel = fis.getChannel();

        final ByteBuffer byteBuffer = ByteBuffer.allocate(1024);

        channel.read(byteBuffer);

        final String str = StrUtil.str(byteBuffer.array(), Charset.defaultCharset());
        System.err.println(str);
        fis.close();
    }
}
